package intelligentcity.model.traffic;

import intelligentcity.conf.Conf;
import intelligentcity.model.Point;
import intelligentcity.model.streets.OneWayStreet;

public class BehaviourOnTurn extends Behaviour {

    public BehaviourOnTurn(Car car) {
        super(car);
    }

    @Override
    public void behave() {

        boolean streetSelected = false;
        streetSelected: if (!streetSelected) {
            for (Point pointOfTurn : currentRoad.getPointsOfTurn()) {
                if (point.equals(pointOfTurn)) {
                    for (OneWayStreet ows : currentRoad.getOneWayStreets()) {
                        if (ows.contains(point) && !ows.equals(currentOWS)) {
                            currentOWS = ows;
                            car.setCurrentOWS(ows);
                            while (!canIMove(ows.getMove(), Conf.distanceBetweenCars * 2)) {
                                Conf.stop(Conf.carStopTimeWhileStreetSelecting);
                            }
                            break streetSelected;
                        }
                    }

                }
            }
        }

    }
}
